package com.taxi.driver.module.order.pool;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.qianxx.adapter.SuperAdapter;
import com.qianxx.adapter.internal.SuperViewHolder;
import com.qianxx.utils.DateUtil;
import com.taxi.driver.R;
import com.taxi.driver.module.vo.OrderSummaryVO;

import java.util.ArrayList;
import java.util.Date;

/**
 * Created by Administrator on 2017/10/18.
 */
public class PoolAdapter extends SuperAdapter<OrderSummaryVO> {

    public PoolAdapter(Context context) {
        super(context, new ArrayList<>(), R.layout.item_order_pool);
    }

    @Override
    public void onBind(SuperViewHolder holder, int viewType, int position, OrderSummaryVO item) {
        String curDate = DateUtil.getPoolTodayOrTomorrow(item.getDepartTime());
        if (position == 0) {
            holder.setVisibility(R.id.tv_date, View.VISIBLE);
        } else {
            OrderSummaryVO previous = mList.get(position - 1);
            String preDate = DateUtil.getPoolTodayOrTomorrow(previous.getDepartTime());
            int vis = curDate.equals(preDate) ? View.GONE : View.VISIBLE;
            holder.setVisibility(R.id.tv_date, vis);
        }
        holder.setText(R.id.tv_date, curDate);
        holder.setText(R.id.tv_start, item.getOriginAddress());
        holder.setText(R.id.tv_end, item.getDestAddress());
        holder.setText(R.id.tv_time, DateUtil.formatDate(new Date(item.getDepartTime()), "HH:mm"));
        if (item.getPlanTrip() == 0d) {
            holder.setVisibility(R.id.tv_trip, View.GONE);
        } else {
            holder.setVisibility(R.id.tv_trip, View.VISIBLE);
            holder.setText(R.id.tv_trip, "全程预计" + item.getPlanTrip() + "公里");
        }

        TextView tvType = holder.getView(R.id.tv_type);
        int resId = OrderSummaryVO.tripType(item.typeTripNew, item.typeTimeNew);
        if (resId == 0) {
            tvType.setVisibility(View.GONE);
        } else {
            tvType.setVisibility(View.VISIBLE);
            tvType.setText(resId);
        }
    }
}
